package com.jijuxie.house.controller;

import com.jijuxie.common.core.R;
import com.jijuxie.house.domain.HouseFacility;
import com.jijuxie.house.service.IHouseFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/house/facility")
public class HouseFacilityController {

    @Autowired
    private IHouseFacilityService facilityService;

    /**
     * 批量添加配套设施
     */
    @PostMapping("/batch")
    public R<Void> batchAdd(@RequestBody List<HouseFacility> facilities) {
        facilityService.batchAddFacilities(facilities);
        return R.ok();
    }

    /**
     * 获取房源的配套设施列表
     */
    @GetMapping("/list/{houseId}")
    public R<List<HouseFacility>> list(@PathVariable Long houseId) {
        return R.ok(facilityService.selectFacilityList(houseId));
    }

    /**
     * 根据类型获取配套设施
     */
    @GetMapping("/list/{houseId}/{type}")
    public R<List<HouseFacility>> listByType(@PathVariable Long houseId, @PathVariable String type) {
        return R.ok(facilityService.selectFacilityListByType(houseId, type));
    }

    /**
     * 获取附近配套设施
     */
    @GetMapping("/nearby/{houseId}")
    public R<List<HouseFacility>> nearby(
            @PathVariable Long houseId,
            @RequestParam(defaultValue = "1000") Integer distance) {
        return R.ok(facilityService.selectNearbyFacilities(houseId, distance));
    }
}
